****************************************
**** Keels, Joo, Wiegand Build File ****
****************************************


* Sample created using: UCDP Conflict Termination Dataset
* Original source: UCDP Conflict Termination Dataset 2015, V.2 (Kreutz 2010)
* Last Access date: 5/7/2019
clear
import excel "Your Directory\RebelSample_Combined.xlsx", sheet("Sheet1") firstrow

* Failures of peace 
* Sample created using: UCDP Conflict Termination Dataset
* Original source: UCDP Conflict Termination Dataset 2015, V.2 (Kreutz 2010)
* Last Access date: 5/7/2019
gen failure=.
replace failure=1 if pend==year
replace failure=0 if failure==.
replace failure=0 if year==2015

gen failure2=.
replace failure2=1 if pend2==year
replace failure2=0 if failure2==.
replace failure2=0 if year==2015

gen failure3=failure
replace failure3=2 if failure2==1 & failure==0
replace failure3=0 if failure3==.


* GDP (log) 
* Original source: WB WDI 
* Last access date: 3/21/2021
merge m:m ccode Year using wb_2
gen lgdp = log(gdp)

* Democracy 
* Original source: Polity V 
* Last access date: 9/16/2020
merge m:m ccode year using polity
gen democracy=1 if polity > 6
replace democracy=0 if democracy==.

* Lootable
* Origianl source: Rebel Contraband Dataset (Joshi and Quinn 2017)
* Last access date: 3/21/2021
merge m:m dyadid year using loot // year is the conflict end year--I had temporarily changed the variable name to merge the data. 

* Lootable Dummy 
gen loot_dum = 0 if loot_sum ==0
replace loot_dum = 1 if loot_sum > 0 

* Political Powersharing, DDR, Land Reform variables 
* Original source: PA-X Dataset v.3 (Bell et al. 2020)
* Last accessed: 3/12/2021
merge peaceid, using "Your Directory\combined_AgreementsData.dta"

* Intensity 
* Original source: UCDP Battle Related Deaths Dyadic Dataset version 5.0-2016
* Last accessed: 3/21/2021
merge m:m conflictid year using intensity // year is the conflict end year--I had temporarily changed the variable name to merge the data. 

gen war = 1 if bdbest >=1000 
replace war = 0 if bdbest <1000
replace war = . if bdbest ==. 

* Number of Rebel Groups in Conflict 
* Original source: UCDP Conflict Termination Dataset 2015, V.2 (Kreutz 2010)
* Last accessed: 7/7/2021
* Note: see R file "build_numreb.R" for code for aggregating the number of groups in a conflict. 
merge m:m ccode conflictid year using numreb3

* Excluded Groups 
* Original source: ACD2EPR Dataset 2019 (Wucherpfennig et al. 2012)
* Last accessed: 12/10/2019 

* Past Agreements  
* Original source: UCDP Conflict Termination Dataset 2015, V.2 (Kreutz 2010)
* Last accessed: 11/17/2022
merge sidebid, using "Your Directory\Pre_1990 Agreements.dta"
replace pre_1990_agreements=0 if pre_1990_agreements==.

* PKO 
* Original source: https://peacekeeping.un.org/en website 
* Authors collected information and coded data by examining the dates and location of all the peacekeeping operations-including paste operations-in the "Where we operate" tab.
* Last accessed: 3/20/2021
merge m:m ccode year using PKO
replace pko=0 if pko==.


* Comprehensive Peace Agreeement 
* Original Source: PA-X dataset version 3 https://pax.peaceagreements.org/agreements/search/ 
* Last accessed: 12/8/2024
merge m:m agtid using pa 

gen comprehensive = 1 if stage == "SubComp"
replace comprehensive = 0 if stage =! "SubComp"
replace comprehensive = . if stage == ""

gen comptime = comprehensive*ltime





